import { findAll } from '@/api/base/table.js'
import { DATA_BASE_SFAPPROVE } from '@/store/mutation-types.js'
const tables = {
  state: {
    tableList: [],
    yjlictable: [],
  },
  // 赋值
  mutations: {
    SET_TABLES: (state, tables) => {
      state.tableList = tables
    },
    SET_YJLIC_TABLES: (state, tables) => {
      state.yjlictable = tables
    },
  },
  // 初始化
  actions: {
    GETTABLES ({ commit }) {
      return new Promise((resolve, reject) => {
        findAll({database: DATA_BASE_SFAPPROVE}).then(res => {
          if (res.code == 0) {
            res.data && res.data.forEach(v => {
              v.title = `${v.tableName} - ${v.notes}`
              v.value = v.tableName
            })
            commit('SET_TABLES', res.data || [])
            resolve(res.data)
          } else {
            reject(-1)
          }
        })
      }).catch(() => {
        reject('枚举列表获取失败！')
      })
    }
  },

  // 取值
  getters: {
  }
}

export default tables